home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / CMD / PLCOMP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-07  |  3.3 KB  |  125 lines

  1. /*
  2.  * the class PLACE_COMPONENT
  3.  * Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #include "../stdafx.h"
  7.  
  8. #include "../common/bool.h"
  9. #include "../resource.h"
  10. #include "plcomp.h"
  11. #include "plcmpdlg.h"
  12.  
  13. #include "../record.h"
  14.  
  15. void PLACE_COMPONENT::PLACE_COMPONENT_MOUSE_CURSOR::draw_cursor_core(KBAN_DRAW& draw, const XY& ac)
  16. {
  17.   m_component.set_ac(ac);
  18.   draw.draw_one_component_cursor(m_component, 0);
  19. }
  20.  
  21. STAGE* PLACE_COMPONENT::init_new(KBAN_INFO& info, KBAN_DRAW& draw)
  22. {
  23.   return new STAGE_INITIAL();
  24. }
  25.  
  26. const char* PLACE_COMPONENT::get_name(void)
  27. {
  28.   return "Place:Component";
  29. }
  30.  
  31. PLACE_COMPONENT::STAGE_INITIAL::STAGE_INITIAL(void)
  32. {
  33. }
  34.  
  35. STAGE *PLACE_COMPONENT::STAGE_INITIAL::init(KBAN_INFO& info, KBAN_DRAW& draw)
  36. {
  37.   CPlaceCompDialog dialog(AfxGetMainWnd());
  38.   STAGE* retval = NULL;
  39.   if(dialog.DoModal() == IDOK) {
  40.     CString comp_name  = dialog.GetComponentName();
  41.     CString designator = dialog.GetDesignator();
  42.     COMPONENT_LIST& list = info.kban_data().component_list();
  43.     // if(list.search_designator(designator) != NULL) {
  44.     if(false) {
  45.       AfxGetMainWnd()->MessageBox("The designator has already been in use", "Place Component");
  46.     } else {
  47.       FILE_NEW fp(comp_name, "r");
  48.       if(!fp.is_ok()) {
  49.         AfxGetMainWnd()->MessageBox("Cannot open the file", "Place Component");
  50.       } else {
  51.         COMPONENT_ELEMENT component;
  52.         KBAN_DATA kban_data;
  53.         kban_data.load(fp);
  54.         component = kban_data.primitive();
  55.         component.set_component_name(comp_name );
  56.         component.set_designator    (designator);
  57.         retval = new STAGE_PLACE_COMPONENT(component);
  58.       }
  59.     }
  60.   }
  61.   return retval;
  62. }
  63.  
  64. PLACE_COMPONENT::STAGE_PLACE_COMPONENT::STAGE_PLACE_COMPONENT(COMPONENT_ELEMENT& component)
  65.   : m_mcur(m_component),
  66.     m_component(component)
  67. {
  68. }
  69.  
  70. STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::redraw(KBAN_INFO& info, KBAN_DRAW& draw)
  71. {
  72.   m_mcur.redraw_cursor(draw);
  73.   return this;
  74. }
  75.  
  76. STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::key_in(KBAN_INFO& info, KBAN_DRAW& draw, UINT key, UINT nFlags)
  77. {
  78.   switch(key) {
  79.     case 'r' :
  80.     case 'R' : {
  81.       m_mcur.erase_cursor(draw);
  82.       m_component.rotate_90();
  83.       break;
  84.     }
  85.   }
  86.   return this;
  87. }
  88.  
  89. STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_move(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  90. {
  91.   XY ac;
  92.   info.grid().xy_pc2ac(pc, ac);
  93.   m_mcur.draw_cursor(draw, ac);
  94.   return this;
  95. }
  96.  
  97. STAGE *PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_left_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  98. {
  99.   m_mcur.erase_cursor(draw);
  100.  
  101.   XY ac;
  102.   info.grid().xy_pc2ac(pc, ac);
  103.  
  104.   COMPONENT_LIST& component_list = info.kban_data().component_list();
  105.  
  106.   m_component.set_ac(ac);
  107.   draw.draw_one_component(m_component, info.active_layer().get());
  108.   component_list.push_back(m_component);
  109.   info.SetModifiedFlag();
  110.   info.new_state().set(true);
  111.   info.new_state_str() = "Place Component";
  112.  
  113.   return new STAGE_INITIAL;
  114. }
  115.  
  116. STAGE *PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_right_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  117. {
  118.   return new STAGE_INITIAL;
  119. }
  120.  
  121. void PLACE_COMPONENT::STAGE_PLACE_COMPONENT::end(KBAN_INFO& info, KBAN_DRAW& draw)
  122. {
  123.   m_mcur.erase_cursor(draw);
  124. }
  125.